/**
 * 
 */
package com.gr.staffpm.pages.dashboard.gadgets;

import org.apache.wicket.extensions.markup.html.repeater.data.sort.OrderByBorder;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.data.DataView;
import org.apache.wicket.spring.injection.annot.SpringBean;

import com.gr.staffpm.datatypes.Task;
import com.gr.staffpm.projects.model.ProjectLink;
import com.gr.staffpm.security.service.UserService;
import com.gr.staffpm.tasks.model.TaskLink;
import com.gr.staffpm.tasks.service.SortableAssignedTaskDataProvider;
import com.gr.staffpm.tasks.service.TaskService;
import com.gr.staffpm.widget.navigator.StaffPMNavigator;


/**
 * @author Graham Rhodes 6 Apr 2011 15:56:01
 */
public class MyAssignedTasksGadget extends Panel {

    @SpringBean(name = "taskService")
    private TaskService taskService;
    @SpringBean(name = "userService")
    private UserService userService;
    private static final long serialVersionUID = 1L;

    public MyAssignedTasksGadget(String id) {
        super(id);

        SortableAssignedTaskDataProvider dp = new SortableAssignedTaskDataProvider(taskService, userService.getCurrentUser());

        final DataView<Task> dataView = new DataView<Task>("assignedTasks", dp) {

            private static final long serialVersionUID = 1L;

            @Override
            protected void populateItem(Item<Task> item) {
                final Task task = item.getModelObject();

                item.add(new ProjectLink("projectLink", task.getProject(), userService).add(new Label("project", task.getProject().getProjectName())));
                item.add(new TaskLink("nameLink", task, userService).add(new Label("name", task.getName())));
                item.add(new TaskLink("statusLink", task, userService).add(new Label("status", task.getStatus().getValue())));
            }
        };
        dataView.setItemsPerPage(10);

        add(new OrderByBorder("orderByProjectName", Task.PROJECT, dp));
        add(new OrderByBorder("orderByTaskName", Task.NAME, dp));

        add(dataView);
        add(new StaffPMNavigator("navigator", dataView));

    }

}
